package br.upe.dsc.caeto.core.project;

import java.util.Iterator;
import br.upe.dsc.caeto.core.IRepository;
import br.upe.dsc.caeto.core.IRegister;
import br.upe.dsc.caeto.core.InvalidElementException;
import br.upe.dsc.caeto.core.ElementNotFoundException;

public class ProjectRegister implements IRegister<Project> {
    IRepository<Project> repository;

    public ProjectRegister(IRepository<Project> projectRepository) {
        this.repository = projectRepository;
    }

    public void add(Project project) throws InvalidElementException {
    	if (project != null) {
    		repository.insert(project);
    	}
    }
    
    public void remove(Project project) throws ElementNotFoundException {
    	if (project != null) {
    		repository.remove(project);
    	}
    }
    
    public void update(Project project) throws ElementNotFoundException,
                                               InvalidElementException {
    	if (project != null) {
    		repository.update(project);
    	}
    }
    
    public Project search(String name) throws ElementNotFoundException {
    	Project project = null;
    	if (name != null) {
    		project = repository.search(name);
    	}
    	return project;
    }
    
    public boolean isElement(String name) {
    	if (name != null) {
    		return repository.isElement(name);
    	}
    	return false;
    }
    
    public void empty() {
    	repository.empty();
    }
    
    public Iterator<Project> iterator() {
    	return repository.iterator();
    }
    
	public Iterable<Project> getElements() {
		return this.repository.getElements();
	}
}